//
//  String+Extensions.swift
//  WeiboSwift
//
//  Created by hfwd on 2017/5/10.
//  Copyright © 2017年 hfwd. All rights reserved.
//

import Foundation

extension String {
    
    /// String使用下标截取字符串
    /// 例: "示例字符串"[0..<2] 结果是 "示例"
    subscript (r: Range<Int>) -> String {
        get {
            
            let startIndex = self.index(self.startIndex, offsetBy: r.lowerBound)
        
            let endIndex = self.index(self.startIndex, offsetBy: r.upperBound)
            
            return self[startIndex..<endIndex]
        }
    }
}
